<?php
namespace app\admin\controller;
use think\Db;
class Sys extends Base
{    
    //编辑
    public function edit(){
        $data = [
            'nav'       => ['系统管理', '系统设置'],
            'list'      => Db::name('sys')->select(),
        ];
        return view('', $data);
    }
    
    //上传图片
    public function upfile($id){
        if( is_post() ){
            if( !isset($_FILES['file']) || in_array($_FILES['file']['type'], ['application/php','application/javascript'])){
                com_error(['上传文件错误!']);
                com_check();
            }else{

                
                if($id==50 && $_FILES['file']['type']!='image/x-icon'){
                    com_error(['网站图标只能上传ico格式的图片']);
                    com_check();
                }
                if(in_array($_FILES['file']['type'], ['image/png', 'image/gif', 'image/jpeg'])){
                    $path = com_up_pic('attach', 'file', false);
                }elseif($_FILES['file']['type']=='image/x-icon' && $id==50){
                    //上传图标
                    $move_file = move_uploaded_file($_FILES['file']['tmp_name'], "favicon.ico");
                    if(!$move_file) {
                        com_error(['上传图标失败']);
                    }else{
                        $path = "./favicon.ico";
                    }
                }else{
                    $path = com_up_file('attach', 'file');
                }
                Db::name('sys')->update(['id'=>$id,'v'=>$path]);
                $config = [
                    'data' => [
                        'path' => $path,
                        'f'    => $id,
                    ],
                ];
                com_check($config);
            }
        }
    }
    
    //清空
    public function del(){
        if(is_post()){
            $id = input('id');
            Db::name("sys")->update(['id'=>$id, 'v'=>'']);
            $config = [
                'suc' => [
                    'msg' => '删除成功!',
                    'js_action' => 'alert',
                ]
            ];
            com_check($config);
        }
    }
}